<?php
$this->headScript()->appendFile($this->APP_STATIC_SERVER . '/js/jquery.validate/jquery.validate.min.js');
?>

<?php
$auth = Zend_Auth::getInstance();
$logined = false;
if ($auth->hasIdentity()) {
    $logined = true;
}
?>
<?php
    $request = Zend_Controller_Front::getInstance()->getRequest();
    $module = $request->getParam('module');
    $action = $request->getParam('action');
?>
<?php
    $skin_url = $this->APP_STATIC_SERVER . '/skins/'. $this->APP_TEMPLATE . '/'. $this->APP_SKIN;
?>
<?php $this->addHelperPath(TOMATO_APP_DIR . DS . 'modules' . DS . 'shoppingcart' . DS . 'views' . DS . 'helpers', 'Shoppingcart_View_Helper');?>
<?php $this->addHelperPath(TOMATO_APP_DIR . DS . 'modules' . DS . 'b2b' . DS . 'views' . DS . 'helpers', 'B2b_View_Helper');?>

<style>
    ul, li { list-style-type:none; }
    #topnav { right:0px; top:0px; }

    .btn_submit {
        background: transparent url(<?php echo $skin_url;?>/html/images/bullet-lang.png) no-repeat;
        width: 16px; height: 15px; text-indent: -999em; border: none; cursor: pointer;
    }

    /*absolute menu*/
    .t_a_ui_mega_menu { width:100%; display:table; }
    .t_a_ui_mega_menu li { float: left; position: relative; line-height: 33px; line-height: 33px; }
    .t_a_ui_mega_menu li:hover span { font-weight:bold; }
    .t_a_ui_mega_menu li a span { padding: 11px 5px 5px 5px; }
    .t_a_ui_mega_menu li.menu-open span {color:#fff; background-color:#DEB57B; font-weight:bold;}
    #topnav a:hover, #topnav a:active, #topnav a:focus {text-decoration:none; z-index:-1000}
    #topnav a { margin: 2px;}

    .absolute_form .hover_form div { text-align: left; margin: 6px 0 6px 0 }
    .absolute_form .hover_form input { padding:  1px 0 1px 0; font-size:13px; color:#555555; }
    .absolute_form .hover_form label { line-height:11px; font-size:9px; font-family:arial; color:#FFFFFF; }
    .absolute_form .hover_form input.error{ color:#FF0000;border: 1px solid;}

    /*absolute login form*/
    .col_140 { float: left; width: 140px; height:1px;}
    .col_105 { float: left; width: 105px; }
    .col_25 { float: left; width: 25px; }
    #signin_menu { display:none; background-color:#DEB57B; position:absolute; z-index:100; top: 27px; right: 0px; *margin-right: -1px;}

    /*absolute register form*/
    .col_290 { float:left; width:290px; }
    .col_270 { float:right; width:270px; }
    .col_270 .col_140 label, .col_270 .col_105 label { text-transform: lowercase; }
    #register_menu { display:none; background-color:#DEB57B; background: transparent url(<?php echo $skin_url;?>/images/register_backgr.png) no-repeat; position:absolute; z-index:100; top: 27px; right: 0px; *margin-right: -1px; }
    #register_menu .border_center { border-left:1px solid; color:#FFFFFF; float:left; height:40px; margin-top:80px; width:35px; }
    #register_menu .register_box { width:609px; height:201px; display:table; }
    #register_menu .hover_form div { text-align: left; margin: 2px 0 3px 0 }

    /*absolute search form*/
    #search_menu { display:none; background-color:#DEB57B; background: transparent url(<?php echo $skin_url;?>/images/search_backgr.png) no-repeat; position:absolute; z-index:100; top: 27px; right: 0px; *margin-right: -1px; }
    #search_menu { width:185px; height:73px; display:table; }
    .col_150 { float:left; width:150px;}
    .col_147 { float:left; width:147px;}
    #search_menu .hover_form div { text-align: left; margin: 2px 0 3px 0 }

</style>

<div id="topnav" role="contentinfo">
    <div style="display:table; width:100%; float:right">
        <ul class="t_a_ui_mega_menu">
            <?php if($logined): ?>
            <?php 
            	$user = $auth->getIdentity();
            	$arrRouteCustomer = array(
                                'user_name' => $user->user_name
                            );
            ?>
            <li style="margin-top:-1px;">
				<span style="text-transform:uppercase;margin:0px;"><?php echo $this->translator('bizprofile_welcome', 'bizprofile');?>!</span>
				<a href="<?php echo $this->url($arrRouteCustomer, 'customer_customer_list'); ?>"><span style="padding-left:0px;padding-right:0px;font-size:12px;font-weight:bold;"><?php echo $user->user_name;?></span></a>
			</li>
            <li><a href="<?php echo $this->url(array(), 'bizprofile_auth_logout'); ?>"><span><?php echo $this->translator('biz_logout_title', 'bizprofile');?></span></a></li>
            <?php else:?>
            <li class="li_signgin">
                <a href="" class="signin"><span style="text-transform: uppercase;"><?php echo $this->translator('auth_login_page_title', 'bizprofile'); ?></span></a>
            </li>
            <li class="li_register">
                <a href="<?php echo $this->url(array(), 'bizprofile_user_register');?>" class="register"><span style='text-transform: uppercase;'><?php echo $this->translator('user_register_title', 'bizprofile'); ?></span></a>
            </li>
            <?php endif;?>
            <li class="li_search">
                <a href="" class="search"><span><?php echo $this->translator('biz_search_title', 'bizprofile');?></span></a>
            </li>
        </ul>
    </div>
</div>

<div class="absolute_form">
    <!--login form-->
    <fieldset id="signin_menu" style="display:none;">
        <form action="<?php echo $this->url(array(), 'bizprofile_auth_login'); ?>" method="POST" id="loginForm" class="hover_form">
            <div class="col_140" style="padding: 0px 0pt 0px 10px;">
                <label style="text-transform: lowercase;"><?php echo $this->translator('auth_login_user_name', 'bizprofile'); ?></label>
                <input type="text" name="username" id="username" style="width:135px;"/>
            </div>
            <div class="col_105">
                <label style="text-transform: lowercase;"><?php echo $this->translator('auth_login_password', 'bizprofile'); ?></label>
                <input type="password" name="password" style="width:100px;"/>
            </div>
            <div class="col_25" style="margin-top: 20px;">
                <input type="submit" value="" class="btn_submit" />
            </div>
        </form>
    </fieldset>

    <!--rigister form-->
    <?php if($module != 'user' && $action != 'register'):?>
    <fieldset id="register_menu" style="display:none;">
        <div class="register_box" style="z-index:1001">
            <div  class="col_290" style="height:131px; text-align:center;">
                <div style="padding-top: 90px">
                    <label style="color:#FFFFFF; font-size: 15px; line-height: 10px;"><?php echo $this->translator('user_register_enterprise_guide', 'bizprofile'); ?></label>
                </div>

                <div style="margin: 5px 0pt 0pt 90px;">
                    <div style="width: 90px; float: left; font-size:8px;">
                        <label style="line-height: 15px;"><a style="color:#AB0000" href="<?php echo $this->url(array(),'bizprofile_user_register_enterprise');?>"><?php echo $this->translator('user_register_enterprise_guide1', 'bizprofile'); ?></a></label>
                    </div>
                    <div style="width: 20px; float: left; margin-left: -8px;">
                        <label style="line-height: 15px;">
                            <a href=""><img src="<?php echo $skin_url;?>/html/images/bullet-lang.png"></a>
                        </label>
                    </div>
                </div>
            </div>

            <div class="border_center"></div>

            <div class="col_270">
                <form action="<?php echo $this->url(array(), 'bizprofile_user_register'); ?>" method="POST" id="registerForm" name="registerForm" class="hover_form">
                    <div style="padding: 5px 0 5px 10px">
                        <label style="color:#FFFFFF; font-size: 10px; line-height: 10px;"><?php echo $this->translator('user_register_guide', 'bizprofile');?></label>
                    </div>
                    <div class="col_140 b_p_left">
                        <label><?php echo $this->translator('user_register_email', 'bizprofile'); ?></label>
                        <input type="text" name="email" style="width:135px;"/>
                    </div>
                    <div class="col_105">
                        <label><?php echo $this->translator('user_register_password', 'bizprofile'); ?></label>
                        <input type="password" name="password" id="password" style="width:100px;"/>
                    </div>
                    <div class="col_140 b_p_left">
                        <label><?php echo $this->translator('user_register_fullname', 'bizprofile'); ?></label>
                        <input type="text" name="full_name" style="width:135px;"/>
                    </div>
                    <div class="col_105">
                        <label><?php echo $this->translator('user_register_confirm_password', 'bizprofile'); ?></label>
                        <input type="password" name="confirmPassword" style="width:100px;"/>
                    </div>
                    <div class="col_140 b_p_left">
                        <label><?php echo $this->translator('user_register_full_address', 'bizprofile'); ?></label>
                        <input type="text" name="address" style="width:135px;"/>
                    </div>
                    <div class="col_105">
                        <label><?php echo $this->translator('user_register_city', 'bizprofile'); ?></label>
                        <input type="text" name="city" style="width:100px;"/>
                    </div>
                    <div class="col_140 b_p_left">
                        <label><?php echo $this->translator('user_register_security_code', 'bizprofile'); ?></label>
                        <span id="img_captcha"></span>
                        <!--<input type="text" name="captcha" value="ANH CAPTCHA" style="width:135px;"/>-->
                    </div>
                    <div class="col_105">
                        <label><?php echo $this->translator('user_register_verify_code', 'bizprofile'); ?></label>
                        <input name="captcha[input]" type="text" style="width:100px"/>
                        <input name="captcha[id]" id="captchaId" type="hidden" value="" />
                    </div>
                    <div style="margin: 5px 0pt 0pt 200px;">
                        <div style="width: 55px; float: left;">
                            <label style="line-height: 15px; font-size:8px;"><a style="color:#AB0000" href="#javascript:document.registerForm.submit()"><?php echo $this->translator('user_register_btn_submit', 'bizprofile'); ?></a></label>
                        </div>
                        <div style="width: 0px; float: left; margin-left: -8px;">
                            <input type="submit" value="" class="btn_submit" />
                        </div>
                    </div>                    
                </form>
            </div>
        </div>
    </fieldset>
    <?php endif;?>

    <!--Search form-->
    <fieldset id="search_menu" style="display:none;">
        <form action="<?php echo $this->url(array(), 'shop_product_search');?>" method="POST" id="searchForm" class="hover_form">
            <div class="col_150" style="padding: 3px 0pt 0px 10px;">
                <label><?php echo $this->translator('biz_simple_keyword', 'bizprofile')?></label>
                <input type="text" name="keyword" style="width:145px;"/>
                <input type="hidden" name="category_id" value="all"/>
            </div>
            <div class="col_25" style="margin-top: 20px;">
                <input type="submit" value="" class="btn_submit" />
            </div>
            <div class="col_147" style="padding: 0px 3px 0px 10px; text-align:right;">
                <label style="line-height:30px"><?php echo $this->translator('biz_advance_search');?></label>
            </div>
            <div class="col_25" style="margin-top: 10px;">
                <img src="<?php echo $skin_url;?>/html/images/bullet-lang.png" />
            </div>
        </form
    </fieldset>
</div>

<div id="logo" class="subcolumns">
    <a href="<?php echo $this->url(array(), 'bizprofile_dashboard_index'); ?>"><h1>Ecommerce</h1></a>
</div>

<div id="nav" role="navigation">
    <div class="hlist">
        <ul>
            <?php
                $params = Zend_Controller_Front::getInstance()->getRequest()->getParams();
            ?>
            <li <?php if($params['module'] == 'core'):?>class="active" <?php endif;?>><a href="<?php echo $this->baseUrl().'/'.$params['lang']; ?>"><span><?php echo $this->translator('homepage', 'bizprofile'); ?></span></a></li>
            <li <?php if($params['module'] == 'shop'):?>class="active" <?php endif;?>><a href="<?php echo $this->url(array(), 'shop_product_all_products');?>"><span><?php echo $this->translator('products', 'bizprofile'); ?></span></a></li>
            <li <?php if($params['module'] == 'bizprofile'):?>class="active" <?php endif;?>><a href="<?php echo $this->url(array(), 'bizprofile_enterprise_list'); ?>"><span><?php echo $this->translator('enterprises', 'bizprofile'); ?></span></a></li>
			<li <?php if($params['module'] == 'news'):?> class="active"<?php endif;?>><a href="<?php echo $this->url(array('category_id'=>2),'news_article_category')?>"><span><?php echo $this->translator('sttNews_title','news');?></span></a></li>
        </ul>
    </div>
    <div class="hlist2">
        <ul>
            <li class="cart"><a href="<?php echo $this->url(array(), 'shoppingcart_shoppingcart_list');?>"><span><?php echo $this->translator('shopping_cart', 'bizprofile'); ?> (<?php echo $this->itemsCart();?>)</span></a></li>
            <?php  if($this->numItems > 0):?>
            <li><a href="<?php echo $this->url(array(),'shoppingcart_shoppingcart_checkout');?>"><span><?php echo $this->translator('cart_checkout_button', 'shoppingcart'); ?></span></a></li>
            <?php  endif;?>
        </ul>
 		
    </div>
    <div class="hlist3">
        <ul>
            <?php echo $this->languageLink();?>
        </ul>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function() {

        /**
        * Login action
        */
        $(".signin").click(function(e) {
            e.preventDefault();
            $("fieldset#signin_menu").toggle();
            $(".li_signgin").toggleClass("menu-open");
        });
        $("fieldset#signin_menu").mouseup(function() {
            return false
        });
        $(document).mouseup(function(e) {
            if($(e.target).parent("a.signin").length==0) {
                $(".li_signgin").removeClass("menu-open");
                $("fieldset#signin_menu").hide();
            }
        });

        <?php if($module != 'user' && $action != 'register'):?>

            /**
            * Validate form
            */
            $('#registerForm').validate({
                rules: {
                    full_name: {
                        required: true
                    },
                    email: {
                        required: true,
                        email: true,
                        remote: '<?php echo $this->url(array('check_type' => 'email'), 'bizprofile_user_check'); ?>'
                    },
                    password: {
                        required: true,
                        minlength: 5
                    },
                    confirmPassword: {
                        equalTo: '#password'
                    },
                    address: {
                        required: true
                    },
                    city: {
                        required: true
                    },
                    "captcha[input]": {
		                required: true,                
		                remote: {
					        url: '<?php echo $this->url(array('check_type' => 'captcha'), 'bizprofile_user_check'); ?>',
					        type: "post",
					        data: {
					          captchaId: function() {
					            return $("#captchaId").val();
					          }
					        }
					    }
		            }
                },
                messages:{
                    full_name: {
                        required: ""
                    },
                    email: {
                        required: "",
                        email: "",
                        remote: ""
                    },
                    password: {
                        required: "",
                        minlength: ""
                    },
                    confirmPassword: {
                        equalTo: ""
                    },
                    address: {
                        required: ""
                    },
                    city: {
                        required: ""
                    },
                    "captcha[input]": {
		                required:'',                
		                remote:''
		            }
                }
            });


            /**
            * Register action
            */
            $(".register").click(function(e) {
                e.preventDefault();
                $("fieldset#register_menu").toggle();
                $(".li_register").toggleClass("menu-open");
            });
            $("fieldset#register_menu").mouseup(function() {
                return false
            });
            $(document).mouseup(function(e) {
                if($(e.target).parent("a.register").length==0) {
                    $(".li_register").removeClass("menu-open");
                    $("fieldset#register_menu").hide();
                }
            });
            /**
            *Get captcha
            **/
            <?php if(!$logined):?>
            $.ajaxq('register', {
                type: 'POST',
                url: "<?php echo $this->url(array(), 'bizprofile_user_captcha'); ?>",
                success: function(response) {
                    arrRes = response.split(';;');
                    id = arrRes[0];
                    word = arrRes[1];
                    img = '<img src="<?php echo $this->APP_STATIC_SERVER ?>/images/captcha/'+id+'.png" alt="Captcha code" />';
                    jQuery('#img_captcha').html(img);
                    jQuery('#captchaId').attr('value', id);                    
                }
            });
            <?php endif;?>
        <?php endif;?>

        /**
        * Search action
        */
        $(".search").click(function(e) {
            e.preventDefault();
            $("fieldset#search_menu").toggle();
            $(".li_search").toggleClass("menu-open");
        });
        $("fieldset#search_menu").mouseup(function() {
            return false
        });
        $(document).mouseup(function(e) {
            if($(e.target).parent("a.search").length==0) {
                $(".li_search").removeClass("menu-open");
                $("fieldset#search_menu").hide();
            }
        });
    });
</script>
